<form id="setting-form" class="form-horizontal" action="/admin/setting/interface" method="post" accept-charset="utf-8">
    {% raw xsrf_form_html() %}
    <div class="form-group">
        <label for="project" class="col-md-2 col-lg-1 control-label">所属项目:</label>
        <div class="col-md-3 col-lg-2">
            <select id="project" name="project" class="form-control">
                <option value="0">请选择项目</option>
                {% for pj in project_list %}
                <option value="{{ pj.id }}">{{ pj.name }}</option>
                {% end %}
            </select>
        </div>
    </div>
    <div class="form-group">
        <label for="label" class="col-md-2 col-lg-1 control-label">接口描述:</label>
        <div class="col-md-6 col-lg-4">
            <textarea style="height:100px;" id="label" name="label" class="form-control" placeholder="简述接口作用及相关事项等"></textarea>
        </div>
    </div>
    <div class="form-group">
        <label for="url" class="col-md-2 col-lg-1 control-label">接口地址:</label>
        <div class="col-md-6 col-lg-4">
            <input type="url" id="url" name="url" class="form-control" placeholder="http(s)://www.bstester.com:8080/interface/test/url">
        </div>
    </div>
    <div class="form-group">
        <div class="col-md-offset-2 col-md-2 col-lg-offset-1 col-lg-1">
            <input type="button" id="submit" value="保存" class="btn btn-primary">
        </div>
    </div>
    <div class="form-group">
        <div class="col-md-offset-2 col-md-2 col-lg-offset-1 col-lg-1">
            <span class="label label-info sr-only" style="font-size:14px;" id="msg"></span>
        </div>
    </div>
    <div class="table-responsive">
        <table class="table table-striped table-hover">
            <thead>
            <tr>
                <th>#</th>
                <th class="col-lg-2">
                    <select id="setting-list" data-op="{{ op }}">
                        <option value="0">所属项目</option>
                        {% for pj in project_list %}
                            {% if pid == pj.id %}
                            <option value="{{ pj.id }}" selected>{{ pj.name }}</option>
                            {% else %}
                            <option value="{{ pj.id }}">{{ pj.name }}</option>
                            {% end %}
                        {% end %}
                    </select>
                </th>
                <th>协议</th>
                <th>Host</th>
                <th>端口</th>
                <th>接口</th>
                <th>接口描述</th>
                <th class="col-lg-2">操作</th>
            </tr>
            </thead>
            <tbody>
            {% for i in range(len(lists)) %}
            <tr data-toggle="tooltip" data-placement="top" title="{{ lists[i].label }}">
                <td>{{ (page-1)*limit+i+1 }}</td>
                <td>{{ lists[i].project_name }}</td>
                <td>{{ lists[i].value.scheme }}</td>
                <td>{{ lists[i].value.host }}</td>
                <td>{{ lists[i].value.port }}</td>
                <td>{{ lists[i].value.path }}</td>
                <td class="inter-detail"><textarea disabled data-sid="{{ lists[i].id }}">{{ lists[i].label }}</textarea></td>
                <td>
                    <a class="btn btn-primary btn-add-check" data-id="{{ lists[i].id }}" data-project="{{ lists[i].project_name }}"
                       data-key="{{ lists[i].key }}">接口配置</a>&nbsp;&nbsp;
                    {% if current_user.role != 2 %}
                    <a class="btn btn-danger btn-delete" data-id="{{ lists[i].id }}">删除</a>
                    {% end %}
                </td>
            </tr>
            {% end %}
            </tbody>
        </table>
        {% module nav(total_page, page, limit, '/admin/setting/interface/{}'.format(pid)) %}
    </div>
</form>
<div class="modal fade" id="interface-key" tabindex="-1" role="dialog" aria-labelledby="keyLabel">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="keyLabel">接口配置</h4>
            </div>
            <form class="form-horizontal" action="/admin/setting/interface/params" method="POST" accept-charset="utf-8">
            {% raw xsrf_form_html() %}
                <div class="modal-body">
                    <div class="form-group">
                        <label class="col-md-2 control-label">所属项目</label>
                        <div class="col-md-4">
                            <label class="control-label project-name"></label>
                            <input type="hidden" name="sid">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-2">返回值检查</label>
                        <div class="col-md-9">
                            <textarea class="form-control" placeholder="此项配置要求接口返回值必须为json格式字符串
                            检查第一层Key值, 一行配置一个, 需要检查子层时, 在第一层的基础上用 .[] 连接子层需要检查的Key值, 格式, key=0|type [非必填|类型] | key=1|type [必填|类型], 如:
                            id=1|int
                            code.[code=1|int,id=1|int,msg=0|str]
                            rows.[0].[code=1|int,id=1|int,msg=0|str]
                            result.rows.[code=1|int,id=1|int,msg=0|str]
                            支持检查的类型有: int|float|num|str|date|time|datetime|list|dict|/正则表达式/" name="keys" style="height:200px;"></textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-2">默认请求Headers</label>
                        <div class="col-md-9">
                            <textarea class="form-control" name="request_headers" placeholder="User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
                                                                                    Content-Type: application/x-www-form-urlencoded; charset=UTF-8
                                                                                    Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4"></textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-2">默认请求Body</label>
                        <div class="col-md-9">
                            <textarea class="form-control" name="request_body" placeholder='请求数据可以是任何格式的字符串, 如是json格式字符串且有加密内容, 请在配置接口测试时, 在【Body加密内容】文本框中输入需要加密的字段key, 仅支持第一层加密, 留空则加密所有内容
            【Response解密内容】填写响应返回需要解密的字段, 格式与【Body加密内容】一样'></textarea>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <span class="label label-info sr-only" style="font-size:14px;" id="tip-msg"></span>
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <input type="button" id="keys-submit-btn" class="btn btn-primary" value="保存">
                </div>
            </form>
        </div>
    </div>
</div>